﻿Imports DAO
Imports System.Windows.Forms

Public Class CondicaoHeader
    Inherits System.Web.UI.UserControl

    Public condicao As Condicao

    Private _campo As String

    Private _tipo As ETipo = ETipo.texto

    Private _operador As EOperador = EOperador.contem 

    Public Event TextChanged()

    Public Sub New()
        MyBase.New()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Enum ETipo
        texto
        numero
    End Enum

    Public Enum EOperador
        maior
        menor
        maiorOuIgual
        menorOuIgual
        diferente
        igual
        null
        contem
    End Enum

    Public Property Tipo As ETipo
        Get
            Return _tipo
        End Get
        Set(ByVal value As ETipo)
            _tipo = value
        End Set
    End Property

    Public Property Operador As EOperador
        Get
            Return _operador
        End Get
        Set(ByVal value As EOperador)
            _operador = value
        End Set
    End Property

    Public WriteOnly Property Width As Integer
        Set(ByVal value As Integer)
            Me.txtCondicaoHeader.Width = value
        End Set
    End Property

    Public WriteOnly Property LabelHeader() As String
        Set(ByVal value As String)
            Me.lblHeader.Text = value
        End Set
    End Property

    Public WriteOnly Property Campo() As String
        Set(ByVal value As String)
            Me._campo = value
        End Set
    End Property

    Public ReadOnly Property TemValor() As Boolean
        Get
            If Me.txtCondicaoHeader.Text <> "" Then
                CarregaDados()
                Return True
            End If
            Return False
        End Get
    End Property

    Private Sub CarregaDados()
        If Me.txtCondicaoHeader.Text <> "" Then
            Me.condicao = New Condicao()
            Me.condicao.Valor = Me.txtCondicaoHeader.Text
            Me.condicao.Campo = Me._campo
            Me.condicao.Operador = Me.Operador.ToString
            Me.condicao.Tipo = Me.Tipo.ToString
        End If
    End Sub

    Public Sub LimparText()
        Me.txtCondicaoHeader.Text = String.Empty
    End Sub

    Protected Sub txtCondicaoHeader_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtCondicaoHeader.TextChanged
        RaiseEvent TextChanged()
    End Sub
    ''Private Sub txtCondicaoHeader_TextChanged(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles txtCondicaoHeader.KeyPress
    ''    If Me.tipo.Equals("numero") Then
    ''        If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8) Then

    ''            e.Handled = True

    ''        End If
    ''    End If

    ''End Sub

    ''Private Sub txtCep_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCondicaoHeader.

    ''End Sub
End Class